<template>
  <div class="user-container">
    <div class="user-box">
      <div class="profile-header">
        <div class="back-nav">
          <div class="back-button" @click="goBack">
            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M19 12H5M12 19l-7-7 7-7"></path>
            </svg>
            <span>返回首页</span>
          </div>
        </div>
        <h2>个人中心</h2>
        <p>您可以查看和管理您的个人信息</p>
      </div>
      
      <div class="profile-content">
        <div class="avatar-section">
          <div class="avatar-container" @click="triggerFileUpload">
            <img v-if="avatarUrl" :src="avatarUrl" alt="用户头像">
            <div v-else class="avatar-placeholder">
              <i class="el-icon-user"></i>
            </div>
            <div class="avatar-overlay">
              <i class="el-icon-camera"></i>
              <span>更换头像</span>
            </div>
          </div>
          <div class="user-name">{{ userInfo.username }}</div>
          <input 
            type="file" 
            ref="fileInput" 
            style="display: none" 
            accept="image/*"
            @change="handleFileChange"
          >
        </div>
        
        <div class="form-section">
          <form class="profile-form" @submit.prevent="handleSubmit">
            <div class="form-row">
              <div class="form-group">
                <label>用户名</label>
                <div class="input-group" :class="{'editable': isEditing}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                      <circle cx="12" cy="7" r="4"></circle>
                    </svg>
                  </div>
                  <input 
                    type="text" 
                    v-model="userInfo.username" 
                    :disabled="!isEditing"
                  >
                </div>
              </div>
              
              <div class="form-group">
                <label>邮箱</label>
                <div class="input-group" :class="{'editable': isEditing}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path>
                      <polyline points="22,6 12,13 2,6"></polyline>
                    </svg>
                  </div>
                  <input 
                    type="email" 
                    v-model="userInfo.email" 
                    :disabled="!isEditing"
                  >
                </div>
              </div>
            </div>
            
            <div class="form-row">
              <div class="form-group">
                <label>手机号 <span class="required-mark">*</span></label>
                <div class="input-group" :class="{'locked': true}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"></path>
                    </svg>
                  </div>
                  <input 
                    type="tel" 
                    v-model="userInfo.mobile" 
                    disabled
                    placeholder="手机号不可修改"
                  >
                  <button type="button" class="edit-mobile-btn" @click="goToResetPhone">
                    <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path>
                    </svg>
                    修改
                  </button>
                </div>
                <span class="info-tip">如需修改，请点击修改按钮</span>
              </div>
              
              <div class="form-group">
                <label>真实姓名 <span class="required-mark">*</span></label>
                <div class="input-group" :class="{'locked': true}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
                      <circle cx="9" cy="7" r="4"></circle>
                      <path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
                      <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
                    </svg>
                  </div>
                  <input 
                    type="text" 
                    v-model="userInfo.real_name" 
                    disabled
                    placeholder="真实姓名不可修改"
                  >
                </div>
                <span class="info-tip">真实姓名一旦设置不可修改</span>
              </div>
            </div>
            
            <div class="form-row">
              <div class="form-group">
                <label>身份证号 <span class="required-mark">*</span></label>
                <div class="input-group" :class="{'locked': true}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <rect x="3" y="4" width="18" height="16" rx="2" ry="2"></rect>
                      <line x1="7" y1="12" x2="17" y2="12"></line>
                      <line x1="7" y1="8" x2="10" y2="8"></line>
                      <line x1="7" y1="16" x2="13" y2="16"></line>
                    </svg>
                  </div>
                  <input 
                    type="text" 
                    :value="maskedIdCard"
                    disabled
                    placeholder="身份证号不可修改"
                  >
                </div>
                <span class="info-tip">身份证号一旦设置不可修改</span>
              </div>
              
              <div class="form-group">
                <label>性别 <span class="required-mark">*</span></label>
                <div class="input-group select-group" :class="{'editable': isEditing}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <circle cx="12" cy="12" r="10"></circle>
                      <path d="M14.31 8l5.74 9.94M9.69 8h11.48M7.38 12l5.74-9.94M9.69 16L3.95 6.06M14.31 16H2.83M16.62 12l-5.74 9.94"></path>
                    </svg>
                  </div>
                  <select v-model="userInfo.gender" :disabled="!isEditing">
                    <option value="male">男</option>
                    <option value="female">女</option>
                    <option value="secrecy">保密</option>
                  </select>
                </div>
                <span class="error-message" v-if="genderError">{{ genderError }}</span>
              </div>
            </div>
            
            <div class="form-row">
              <div class="form-group">
                <label>出生日期</label>
                <div class="input-group" :class="{'editable': isEditing}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
                      <line x1="16" y1="2" x2="16" y2="6"></line>
                      <line x1="8" y1="2" x2="8" y2="6"></line>
                      <line x1="3" y1="10" x2="21" y2="10"></line>
                    </svg>
                  </div>
                  <input 
                    type="date" 
                    v-model="userInfo.birth_date" 
                    :disabled="!isEditing"
                  >
                </div>
              </div>
              
              <div class="form-group">
                <label>学历</label>
                <div class="input-group select-group" :class="{'editable': isEditing}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <path d="M22 10v6M2 10l10-5 10 5-10 5z"></path>
                      <path d="M6 12v5c3 3 9 3 12 0v-5"></path>
                    </svg>
                  </div>
                  <select v-model="userInfo.education" :disabled="!isEditing">
                    <option value="高中">高中</option>
                    <option value="专科">专科</option>
                    <option value="本科">本科</option>
                    <option value="硕士">硕士</option>
                    <option value="博士">博士</option>
                  </select>
                </div>
              </div>
            </div>
            
            <div class="form-row">
              <div class="form-group full-width">
                <label>学校</label>
                <div class="input-group" :class="{'editable': isEditing}">
                  <div class="input-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                      <path d="M12 3L2 12h3v8h14v-8h3L12 3z"></path>
                    </svg>
                  </div>
                  <input 
                    type="text" 
                    v-model="userInfo.school" 
                    :disabled="!isEditing"
                  >
                </div>
              </div>
            </div>
            
            <div class="form-row" v-if="userDetailsInfo && userDetailsInfo.role !== 'teacher'">
              <div class="form-group full-width">
                <label>学习风格偏好</label>
                <div class="checkbox-group" :class="{'editable': isEditing}">
                  <div v-for="(style, index) in learningStyles" :key="index" class="checkbox-item">
                    <input 
                      type="checkbox" 
                      :id="'style-' + index" 
                      :checked="userPreferences[style.value] === 1"
                      :disabled="!isEditing"
                      @change="updatePreference(style.value, $event)"
                    >
                    <label :for="'style-' + index">{{ style.label }}</label>
                  </div>
                </div>
              </div>
            </div>
            
            <div class="action-buttons">
              <button 
                v-if="!isEditing" 
                type="button" 
                class="edit-btn" 
                @click="startEditing"
              >
                编辑资料
              </button>
              <template v-else>
                <button type="submit" class="save-btn">保存</button>
                <button type="button" class="cancel-btn" @click="cancelEditing">取消</button>
              </template>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserDetailsInfo, updateUserInfo, uploadAvatar } from '@/api/user'
import { ElMessage } from 'element-plus'
import eventBus from '@/utils/eventBus'

export default {
  name: 'UserInfoView',
  data() {
    return {
      isEditing: false,          // 编辑状态
      originalUserInfo: null,    // 原始用户信息
      userInfo: {
        username: '',           // 用户名
        email: '',             // 邮箱
        mobile: '',            // 手机号
        real_name: '',         // 真实姓名
        id_card: '',           // 身份证号
        gender: '',            // 性别
        birth_date: '',        // 出生日期
        education: '',         // 学历
        school: '',            // 学校
        preferences: []        // 偏好设置
      },
      defaultAvatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png', // 默认头像
      avatarUrl: '',           // 头像URL
      uploadLoading: false,    // 上传状态
      interests: [             // 兴趣选项
        { label: '阅读', value: 'reading' },
        { label: '音乐', value: 'music' },
        { label: '电影', value: 'movies' },
        { label: '旅行', value: 'travel' },
        { label: '体育', value: 'sports' },
        { label: '编程', value: 'coding' },
        { label: '绘画', value: 'drawing' },
        { label: '摄影', value: 'photography' }
      ],
      learningStyles: [        // 学习风格选项
        { label: '传统', value: 'traditionalStyle' },
        { label: '互动讨论', value: 'interactiveDiscussionStyle' },
        { label: '案例分析', value: 'caseStudyStyle' },
        { label: '游戏化教学', value: 'gamifiedLearningStyle' },
        { label: '情感激励', value: 'emotionalMotivationStyle' },
        { label: '幽默', value: 'humorousStyle' },
        { label: '引导式教学', value: 'guidedLearningStyle' },
        { label: '个性化学习', value: 'personalizedLearningStyle' },
        { label: '翻转课堂', value: 'flippedClassroomStyle' }
      ],
      userPreferences: {},     // 用户偏好设置
      userDetailsInfo: null,   // 用户详细信息
      genderError: ''          // 性别错误信息
    }
  },
  computed: {
    // 身份证号脱敏显示
    maskedIdCard() {
      const idCard = this.userInfo.id_card;
      if (!idCard) return '';
      if (idCard.length <= 8) return idCard;
      
      const prefix = idCard.substring(0, 4);
      const suffix = idCard.substring(idCard.length - 4);
      return `${prefix}**********${suffix}`;
    }
  },
  created() {
    this.fetchUserDetailsInfo()
  },
  methods: {
    // 获取用户详细信息
    async fetchUserDetailsInfo() {
      try {
        const response = await getUserDetailsInfo()
        
        if (response.code === 200) {
          this.userDetailsInfo = response.data
          
          // 处理用户学习风格偏好
          if (this.userDetailsInfo) {
            // 处理用户头像
            if (this.userDetailsInfo.ossImages && this.userDetailsInfo.ossImages.length > 0) {
              // 查找类型为head的图片作为头像
              const headImage = this.userDetailsInfo.ossImages.find(img => img.relationType === 'head');
              if (headImage) {
                this.avatarUrl = headImage.url;
              }
            }
            
            // 如果存在用户偏好
            if (this.userDetailsInfo.userPreferences) {
              const preferences = this.userDetailsInfo.userPreferences
              
              // 将字符串转换为数字，并处理可能的空值或 null
              const processPreference = (value) => {
                if (value === null || value === undefined || value === '') return 0
                return parseInt(value) || 0
              }
              
              // 初始化偏好对象
              this.userPreferences = {
                traditionalStyle: processPreference(preferences.traditionalStyle),
                interactiveDiscussionStyle: processPreference(preferences.interactiveDiscussionStyle),
                caseStudyStyle: processPreference(preferences.caseStudyStyle),
                gamifiedLearningStyle: processPreference(preferences.gamifiedLearningStyle),
                emotionalMotivationStyle: processPreference(preferences.emotionalMotivationStyle),
                humorousStyle: processPreference(preferences.humorousStyle),
                guidedLearningStyle: processPreference(preferences.guidedLearningStyle),
                personalizedLearningStyle: processPreference(preferences.personalizedLearningStyle),
                flippedClassroomStyle: processPreference(preferences.flippedClassroomStyle)
              }
            } else {
              // 如果没有偏好信息，初始化为空对象
              this.userPreferences = {
                traditionalStyle: 0,
                interactiveDiscussionStyle: 0,
                caseStudyStyle: 0,
                gamifiedLearningStyle: 0,
                emotionalMotivationStyle: 0,
                humorousStyle: 0,
                guidedLearningStyle: 0,
                personalizedLearningStyle: 0,
                flippedClassroomStyle: 0
              }
            }
            
            // 更新基本用户信息
            const detailsInfo = this.userDetailsInfo
            
            // 使用后端返回的原始性别值：male/female/secrecy
            const genderValue = detailsInfo.gender || this.userInfo.gender
            
            // 处理出生日期：将ISO格式转换为YYYY-MM-DD格式
            let birthDateValue = this.userInfo.birth_date
            if (detailsInfo.birthDate) {
              try {
                // 尝试将日期格式化为 YYYY-MM-DD
                const date = new Date(detailsInfo.birthDate)
                birthDateValue = date.toISOString().split('T')[0]
              } catch (e) {
                birthDateValue = detailsInfo.birthDate // 使用原始值
              }
            }
            
            // 更新用户信息
            this.userInfo = {
              username: detailsInfo.userName || '',
              email: detailsInfo.email || '',
              mobile: detailsInfo.mobile || '',
              real_name: detailsInfo.realName || '',
              id_card: detailsInfo.idCard || '',
              gender: genderValue,
              birth_date: birthDateValue,
              education: detailsInfo.education || '',
              school: detailsInfo.school || ''
            }
            
            // 保存原始信息用于取消编辑
            this.originalUserInfo = JSON.parse(JSON.stringify(this.userInfo))
          }
        } else {
          ElMessage.error('获取用户信息失败: ' + (response.message || '未知错误'))
        }
      } catch (error) {
        ElMessage.error('获取用户详细信息失败，请稍后重试')
      }
    },
    // 开始编辑
    startEditing() {
      this.isEditing = true;
      this.genderError = ''; // 重置错误信息
    },
    // 取消编辑
    cancelEditing() {
      // 恢复原始用户数据
      this.userInfo = JSON.parse(JSON.stringify(this.originalUserInfo));
      
      // 如果原始数据中有保存的偏好信息，恢复它
      if (this.originalUserInfo && this.originalUserInfo.userPreferences) {
        this.userPreferences = JSON.parse(JSON.stringify(this.originalUserInfo.userPreferences));
      }
      
      this.isEditing = false;
      this.genderError = ''; // 重置错误信息
    },
    // 提交表单
    async handleSubmit() {
      try {
        // 重置所有错误信息
        this.genderError = '';
        
        // 校验性别是否填写
        if (!this.userInfo.gender) {
          this.genderError = '请选择性别';
          ElMessage.error('请选择性别');
          return;
        }
        
        // 只验证邮箱格式
        if (this.userInfo.email && !this.isValidEmail(this.userInfo.email)) {
          ElMessage.error('邮箱格式不正确');
          return;
        }
        
        // 按照后端需要的格式准备提交数据
        const userData = {
          userName: this.userInfo.username,
          email: this.userInfo.email,
          // 手机号、真实姓名和身份证号不允许修改，直接从原始数据获取
          mobile: this.originalUserInfo.mobile,
          realName: this.originalUserInfo.real_name,
          idCard: this.originalUserInfo.id_card,
          // 性别值已经是英文，无需转换
          gender: this.userInfo.gender,
          // 确保日期格式为YYYY-MM-DD
          birthDate: this.userInfo.birth_date || '',
          education: this.userInfo.education,
          school: this.userInfo.school,
          userPreferences: {
            traditionalStyle: this.userPreferences.traditionalStyle.toString(),
            interactiveDiscussionStyle: this.userPreferences.interactiveDiscussionStyle.toString(),
            caseStudyStyle: this.userPreferences.caseStudyStyle.toString(),
            gamifiedLearningStyle: this.userPreferences.gamifiedLearningStyle.toString(),
            emotionalMotivationStyle: this.userPreferences.emotionalMotivationStyle.toString(),
            humorousStyle: this.userPreferences.humorousStyle.toString(),
            guidedLearningStyle: this.userPreferences.guidedLearningStyle.toString(),
            personalizedLearningStyle: this.userPreferences.personalizedLearningStyle.toString(),
            flippedClassroomStyle: this.userPreferences.flippedClassroomStyle.toString()
          }
        }
        
        // 调用API更新用户信息
        const response = await updateUserInfo(userData)
        
        if (response.code === 200) {
          ElMessage.success('保存成功')
          
          // 更新原始数据
          this.originalUserInfo = JSON.parse(JSON.stringify(this.userInfo))
          
          // 重新获取用户详细信息
          await this.fetchUserDetailsInfo()
          
          // 退出编辑模式
          this.isEditing = false
        } else {
          throw new Error(response.message || '更新失败')
        }
      } catch (error) {
        ElMessage.error(error.message || '保存失败，请稍后重试')
      }
    },
    // 更新偏好设置
    updatePreference(value, event) {
      if (event.target.checked) {
        this.userPreferences[value] = 1
      } else {
        this.userPreferences[value] = 0
      }
    },
    // 验证邮箱格式
    isValidEmail(email) {
      const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
      return emailRegex.test(email);
    },
    // 验证手机号格式
    isValidMobile(mobile) {
      const mobileRegex = /^1[3-9]\d{9}$/;
      return mobileRegex.test(mobile);
    },
    // 跳转到重置手机号页面
    goToResetPhone() {
      this.$router.push('/phone-reset')
    },
    // 触发文件选择对话框
    triggerFileUpload() {
      this.$refs.fileInput.click();
    },
    
    // 处理文件选择
    async handleFileChange(e) {
      const file = e.target.files[0];
      if (!file) return;
      
      // 验证文件类型
      const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/jpg'];
      if (!validTypes.includes(file.type)) {
        ElMessage.error('请上传JPG、PNG或GIF格式的图片');
        return;
      }
      
      // 验证文件大小，限制为2MB
      const maxSize = 2 * 1024 * 1024; // 2MB
      if (file.size > maxSize) {
        ElMessage.error('图片大小不能超过2MB');
        return;
      }
      
      // 上传文件
      try {
        this.uploadLoading = true;
        ElMessage.info('头像上传中...');
        
        const response = await uploadAvatar(file);
        
        if (response.code === 200) {
          const imageUrl = response.data;
          this.avatarUrl = imageUrl;
          ElMessage.success('头像上传成功');
          
          // 上传成功后重新获取用户信息以同步头像信息
          await this.fetchUserDetailsInfo();
          
          // 触发头像更新事件，通知其他组件（如导航栏）更新头像
          eventBus.emit('avatar-updated');
        } else {
          ElMessage.error(response.message || '头像上传失败');
        }
      } catch (error) {
        ElMessage.error('头像上传失败，请稍后重试');
      } finally {
        this.uploadLoading = false;
        // 清空文件输入，允许重新选择同一文件
        this.$refs.fileInput.value = '';
      }
    },
    // 返回首页
    goBack() {
      this.$router.push('/home')
    },
    // 保存头像URL
    async saveAvatarUrl(url) {
      try {
        // 构建头像数据
        const avatarData = {
          ossImage: {
            url: url,
            relationType: 'head'
          }
        }
        
        // 发送请求更新头像
        const response = await updateUserInfo(avatarData)
        if (response.code === 200) {
          // 更新本地头像
          this.avatarUrl = url
          // 触发导航栏头像更新
          eventBus.emit('avatar-updated', url)
        } else {
          ElMessage.error('保存头像URL失败')
        }
      } catch (error) {
        ElMessage.error('保存头像URL时发生错误')
      }
    },
  }
}
</script>

<style scoped>
.user-container {
  min-height: 100vh;
  background: #f5f7fa;
  font-family: "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
}

.user-box {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.profile-header {
  background: linear-gradient(135deg, #58656D, #3d4750);
  color: white;
  padding: 40px;
  border-radius: 10px 10px 0 0;
  margin-top: 20px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.profile-header h2 {
  margin: 0 0 10px 0;
  font-size: 28px;
  font-weight: 600;
}

.profile-header p {
  opacity: 0.8;
  font-size: 14px;
  margin: 0;
}

.back-nav {
  margin-bottom: 16px;
  position: relative;
  z-index: 10;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: all 0.3s;
  color: white;
  font-weight: 500;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.back-button svg {
  stroke-width: 2.5;
}

.profile-content {
  background: white;
  border-radius: 0 0 10px 10px;
  padding: 40px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  margin-bottom: 40px;
}

.avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  background-color: #f0f2f5;
  border-radius: 10px;
  margin-bottom: 30px;
  text-align: center;
}

.avatar-container {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 1rem;
  background-color: #e9ebed;
  border: 3px solid #fff;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  position: relative;
  cursor: pointer;
}

.avatar-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #e9ebed;
  color: #58656D;
  font-size: 48px;
}

.avatar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  opacity: 0;
  transition: opacity 0.3s;
}

.avatar-overlay i {
  font-size: 24px;
  margin-bottom: 5px;
}

.avatar-overlay span {
  font-size: 12px;
}

.avatar-container:hover .avatar-overlay {
  opacity: 1;
}

.user-name {
  font-size: 1.2rem;
  font-weight: 600;
  color: #333;
}

.form-section {
  margin-top: 30px;
}

.form-row {
  display: flex;
  gap: 20px;
  margin-bottom: 28px;
  align-items: flex-start;
}

.form-group {
  flex: 1;
  margin-bottom: 15px;
}

.form-group.full-width {
  flex: 100%;
  width: 100%;
}

.form-group label {
  display: block;
  margin-bottom: 10px;
  font-weight: 500;
  color: #333;
}

.required-mark {
  color: #f56c6c;
  margin-left: 4px;
}

.input-group {
  position: relative;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  transition: all 0.3s;
}

.input-group:focus-within {
  border-color: #58656D;
  box-shadow: 0 0 0 2px rgba(88, 101, 109, 0.2);
}

.input-group.locked {
  background-color: #f6f8fa;
}

.input-group.editable {
  background-color: #fff;
}

.input-icon {
  padding: 0 15px;
  color: #58656D;
  display: flex;
  align-items: center;
}

.input-group input, 
.input-group select {
  flex: 1;
  height: 45px;
  padding: 0 15px;
  border: none;
  background: transparent;
  color: #606266;
  font-size: 14px;
  outline: none;
  width: 100%;
}

.input-group input:disabled, 
.input-group select:disabled {
  cursor: not-allowed;
  color: #909399;
  background-color: transparent;
}

.error-tip {
  color: #f5222d;
  font-size: 12px;
  margin-top: 5px;
}

.info-tip {
  color: #666;
  font-size: 12px;
  margin-top: 5px;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 30px;
}

.edit-btn,
.save-btn,
.cancel-btn {
  padding: 12px 30px;
  border-radius: 12px;
  font-weight: 500;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
}

.edit-btn {
  background-color: #58656D;
  color: white;
}

.edit-btn:hover {
  background-color: #4a5760;
}

.save-btn {
  background-color: #58656D;
  color: white;
}

.save-btn:hover {
  background-color: #4a5760;
}

.cancel-btn {
  background-color: #f0f0f0;
  color: #555;
}

.cancel-btn:hover {
  background-color: #e0e0e0;
}

.edit-mobile-btn {
  background-color: #ffffff;
  color: #58656D;
  border: none;
  border-radius: 0 10px 10px 0;
  padding: 0 15px;
  height: 100%;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: inset 1px 0 0 #e5e7eb;
}

.edit-mobile-btn:hover {
  background-color: #f0f2f5;
  color: #4a5760;
}

.edit-mobile-btn svg {
  margin-top: -2px;
}

@media (max-width: 768px) {
  .user-box {
    padding: 0 10px;
  }
  
  .profile-header {
    padding: 30px 20px;
  }
  
  .profile-content {
    padding: 30px 20px;
  }
  
  .form-row {
    flex-direction: column;
    gap: 15px;
  }
  
  .form-group {
    width: 100%;
  }
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 5px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  min-width: 100px;
  margin-right: 15px;
  margin-bottom: 10px;
}

.checkbox-item input[type="checkbox"] {
  margin-right: 6px;
}

.checkbox-item label {
  margin-bottom: 0;
  font-weight: normal;
  cursor: pointer;
}

.error-message {
  color: #f56c6c;
  font-size: 12px;
  margin-top: 4px;
  display: block;
}
</style>